﻿using System.Linq;
using System.Web.Mvc;
using Complaint.Models;

namespace Complaint.Controllers
{
    public class LeftNavController : Controller
    {
        //
        // GET: /LeftNav/DisplayLatestComplaints
        public ActionResult DisplayLatestComplaints()
        {
            using (new UnitOfWorkScope(false))
            {
                var model = new ComplaintModel();
                var complaints = model.Retrieve(5);
                return View("LatestComplaints", complaints);
            }
        }

        //
        // GET: /LeftNav/DisplayCategories
        public ActionResult DisplayCategories()
        {
            using (new UnitOfWorkScope(false))
            {
                var model = new CategoryModel();
                //var categories = model.GetCategoryHierarchy(null);
                var categories = model.GetPopularRoots(5);
                return View("Categories", categories);
            }
        }

        public ActionResult GetUserDisplayName()
        {
            if (Request.IsAuthenticated)
            {
                using (new UnitOfWorkScope(false))
                {
                    var model = new UserModel();
                    var user = model.FindByName(User.Identity.Name).FirstOrDefault();
                    ViewData["DisplayName"] = user.DisplayName;

                }
            }
            return View("LogOnUserControl");
        }
    }
}
